<?php

require_once 'Basic.php';

class EntityTest extends BasicEntity {
  
  private $id;
  private $actionDescription;
  
  private function initFields($actionDescription) {
    $this->actionDescription = $actionDescription;
    switch($actionDescription) {
      case "Create":
        $this->fields = array(
          new FormField(true, 'nome1', 'Primeiro Nome', new FormFieldTextLine()),
          new FormField(true, 'email', 'Email', new FormFieldGmail()),
          new FormField(true, 'cpf',   'CPF (apenas d&iacute;gitos)', new FormFieldCPF())
        );
        break;
      case "Remove":
        $this->fields = array();
        break;
      case "Edit":
        $this->fields = array(
          new FormField(true,  'nome1', 'Primeiro Nome', new FormFieldTextLine()),
          new FormField(false, 'nome2', 'Segundo Nome', new FormFieldTextLine()),
          new FormField(false, 'nascimento', 'Data de Nascimento', new FormFieldBirthDate()),
          new FormField(true,  'email', 'Email', new FormFieldGmail()),
          new FormField(false, 'emailsec', 'Email secund&aacute;rio', new FormFieldGmail()),
          new FormField(true,  'cpf', 'CPF (apenas d&iacute;gitos)', new FormFieldCPF())
        );
        break;
      default:
        throw new Exception("Invalid action description given: ${actionDescription}.");
        break;
    }
    $this->processFields();
  }
  
  public function __construct($id = null, $remove = false) {
    if($id === null) {
      $this->id = null;
      EntityTest::initFields("Create");
      if($remove === true) {
        throw new Exception("True remove for null id.");
      }
    }
    else {
      $this->id = $id;
      if($remove === true) {
        EntityTest::initFields("Remove");
      }
      else {
        EntityTest::initFields("Edit");
      }
    }
  }
  
  public function actionDescription() {
    return $this->actionDescription;
  }

  public function actionCreate($userInput) {
    return true;
  }
  
  public function actionEdit($userInput) {
    return true;
  }
  
  public function actionRemove($userInput) {
    return true;
  }
  
}
